# file1 = open('data2.txt', 'r', encoding='utf-8')  # 打开要去掉空行的文件
# file2 = open('data3.txt', 'w', encoding='utf-8')  # 生成没有空行的文件
#
# for line in file1.readlines():
#     if line == '\n':
#         line = line.strip('\n')
#         file2.write(line)
#         file1.close()
#         file2.close()


def add_blank_line(filename, word):
    with open(filename, 'r', encoding='utf-8') as file:
        lines = file.readlines()

        # 重新打开文件以便写入
    with open(filename, 'w') as file:
        for i, line in enumerate(lines):
            if word in line:
                # 如果单词在行中，下一行添加一个空行
                if i < len(lines) - 1:
                    file.write(lines[i + 1])
                    file.write('\n')  # 写入空行
            else:
                file.write(line)

            # 使用方法


add_blank_line('data3.txt', '答案解析')
